package com.xrui.hbaseview.ui;

import com.google.common.base.Preconditions;

import javax.swing.*;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

public class Images {

    private static Map<String, ImageIcon> images;

    static {
        images = new HashMap<>();
    }

    private Images() {
    }

    public static ImageIcon get(String name) {
        if (images.containsKey(name)) {
            return images.get(name);
        }
        URL url = Thread.currentThread().getContextClassLoader().getResource(String.format("images/%s.png", name));
        ImageIcon icon = new ImageIcon(Preconditions.checkNotNull(url));
        images.put(name, icon);

        return icon;
    }
}
